package com.example.xyxwebbackend001.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xyxwebbackend001.model.entity.Tourist;
import com.example.xyxwebbackend001.model.vo.ComArtDetailsVO;
import com.example.xyxwebbackend001.model.vo.CommendListVO;
import com.example.xyxwebbackend001.model.vo.FoodListVO;
import com.example.xyxwebbackend001.model.vo.TouristListVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface TouristMapper extends BaseMapper<Tourist> {
    @Select("<script>"
            + "SELECT to_id as commend_id, title, city_id, cover_path FROM tourist "
            + "WHERE status = 1 "
            + "<if test='cityId != null'>"
            + "    AND city_id = #{cityId} "
            + "</if>"
            + "</script>")
    List<CommendListVO> getTouristListByCityId(@Param("cityId") String cityId);

    ComArtDetailsVO selectTouristDetailsById(@Param("touristId")String touristId);

    @Select("<script>" +
            "SELECT " +
            "   t.to_id AS id," +  // 修改表别名为t
            "   t.title," +
            "   c.city_name AS cityName," +
            "   t.status," +
            "   DATE_FORMAT(t.create_time, '%Y-%m-%d %H:%i:%s') AS createTime " +
            "FROM tourist t " +  // 修正表名为tourist
            "LEFT JOIN city c ON t.city_id = c.city_id COLLATE utf8mb4_general_ci " +
            "WHERE t.status != 2 " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "   AND t.title LIKE CONCAT('%', #{keyword}, '%')" +
            "</if> " +
            "ORDER BY t.create_time DESC" +
            "</script>")
    List<TouristListVO> getTouristList(@Param("keyword") String keyword);
}
